/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * TelaDoJogador.java
 *
 * Created on 28/11/2011, 16:53:54
 */
package GUI;

import BLL.GerenciadorJogo;
import DAL.Conexao;
import javax.swing.JOptionPane;

/**
 *
 * @author Vanessa
 */
public class TelaDoJogador extends javax.swing.JPanel {
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTable1;
    private String nomeJogador;
    
    public TelaDoJogador() {
        initComponents();
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        botaoRanking = new javax.swing.JButton();
        botaoJogar = new javax.swing.JButton();
        botaoSair = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();

        setLayout(null);

        botaoRanking.setText("RANKING");
        botaoRanking.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botaoRankingActionPerformed(evt);
            }
        });
        add(botaoRanking);
        botaoRanking.setBounds(20, 290, 100, 23);

        botaoJogar.setText("JOGAR");
        botaoJogar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botaoJogarActionPerformed(evt);
            }
        });
        add(botaoJogar);
        botaoJogar.setBounds(20, 340, 100, 23);

        botaoSair.setText("SAIR");
        botaoSair.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botaoSairActionPerformed(evt);
            }
        });
        add(botaoSair);
        botaoSair.setBounds(20, 390, 100, 23);

        jLabel1.setIcon(new javax.swing.ImageIcon("I:\\PI\\2012\\src\\GUI\\2012.jpg")); // NOI18N
        add(jLabel1);
        jLabel1.setBounds(0, 0, 570, 520);
    }// </editor-fold>//GEN-END:initComponents

    private void botaoRankingActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botaoRankingActionPerformed
        Conexao cx = new Conexao();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        cx.ranking();
        String[] nomeJogador = cx.getNomeJogadorRanking();
        String[] nomePartida = cx.getNomePartidaRanking();
        String[] ponto = cx.getPontosRanking();
                
        setBackground(new java.awt.Color(0, 0, 0));
        setLayout(null);
        
        jTable1.setFont(new java.awt.Font("Times New Roman", 0, 14)); // NOI18N
        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {nomeJogador[0], nomePartida[0], ponto[0]},
                {nomeJogador[1], nomePartida[1], ponto[1]},
                {nomeJogador[2], nomePartida[2], ponto[2]},
                {nomeJogador[3], nomePartida[3], ponto[3]},
                {nomeJogador[4], nomePartida[4], ponto[4]},
                {nomeJogador[5], nomePartida[5], ponto[5]},
                {nomeJogador[6], nomePartida[6], ponto[6]},
                {nomeJogador[7], nomePartida[7], ponto[7]},
                {nomeJogador[8], nomePartida[8], ponto[8]},
                {nomeJogador[9], nomePartida[9], ponto[9]},
            },
            new String [] {
                "Jogador", "Partida", "Pontos"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class, java.lang.Integer.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane1.setViewportView(jTable1);

        add(jScrollPane1);
        jScrollPane1.setBounds(110, 60, 452, 190);;
           
    }//GEN-LAST:event_botaoRankingActionPerformed

    private void botaoSairActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botaoSairActionPerformed
        System.exit(0);
    }//GEN-LAST:event_botaoSairActionPerformed

    private void botaoJogarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botaoJogarActionPerformed
        Conexao cx = new Conexao();
        boolean existe = cx.existePartidaAtiva(nomeJogador);
        int i;
        GerenciadorJogo gj = new GerenciadorJogo();
        if(existe == true){
            i = JOptionPane.showConfirmDialog(null, "Deseja continuar o jogo salvo?");
            if(i == 0){
                gj.executarSistema(5);
            }
            else{
                cx.desativaPartida(nomeJogador);
                gj.executarSistema(1);
            }
        }
        else{
            gj.executarSistema(1);
        }
    }//GEN-LAST:event_botaoJogarActionPerformed

    public void setNomeJogador(String jogador){
        nomeJogador = jogador;
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton botaoJogar;
    private javax.swing.JButton botaoRanking;
    private javax.swing.JButton botaoSair;
    private javax.swing.JLabel jLabel1;
    // End of variables declaration//GEN-END:variables
}
